package com.mitgroup.dmrvs.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mitgroup.dmrvs.R;
import com.mitgroup.dmrvs.adapter.NoticeAdapter;

import java.util.ArrayList;
import java.util.List;



public class DispImageDialog extends Dialog {

    private ViewPager mViewPager;
    private String mSpareParts;
    public DispImageDialog(@NonNull Context context,String spareParts) {
        //设置自定义Dialog的主题风格
        super(context, R.style.selfDefDialog);
        mSpareParts=spareParts;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置Dialog的显示方式：alpha :0->1
        getWindow().setWindowAnimations(R.style.popupAnimation);
        //设置Dialog布局
        setContentView(R.layout.dialog_layout);
        mViewPager = (ViewPager) findViewById(R.id.viewpager);
        mViewPager.setAdapter(createAdapter());
    }

    private PagerAdapter createAdapter() {
        List<View> adapterViews = new ArrayList<>();
        String productArr[]=mSpareParts.split(",");
        String productStr="";
        for (int i=0;i<productArr.length;i++) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.adapter_view_layout, null);
            TextView tvTitle = (TextView) view.findViewById(R.id.tv_adapter_title);
            tvTitle.setText("第" + (i + 1) + "张("+productArr.length+")");
            ImageView ivSparePart=(ImageView) view.findViewById(R.id.iv_spare_part);
            productStr=productArr[i];
            if("wa11000".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa11000));

            }
            else if("wa66101".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa66101));
            }
            else if("wa68102".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa68102));
            }
            else if("wa60802".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa60802));
            }
            else if("wa61510".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa61510));
            }
            else if("wa64401".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa64401));
            }
            else if("wa64506".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa64506));
            }
            else if("waa4701".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.waa4701));
            }
            else if("waa4601".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.waa4601));
            }
            else if("wa62409".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa62409));
            }
            else if("wa64805".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa64805));
            }
            else if("wa66701".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa66701));
            }
            else if("wa30208".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa30208));
            }
            else if("wa62801".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa62801));
            }
            else if("wa67104".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa67104));
            }
            else if("wa65221".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa65221));
            }
            else if("wa61610".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa61610));
            }
            else if("wa64328".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa64328));
            }
            else if("wa63614".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa63614));
            }
            else if("wa78501".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa78501));
            }
            else if("wa9920t".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa9920t));
            }
            else if("wa52630".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa52630));
            }
            else if("wa66601".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa66601));
            }
            else if("wa8860t".equals(productStr))
            {
                ivSparePart.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.wa8860t));
            }
            adapterViews.add(view);
        }

        return new NoticeAdapter(adapterViews);

    }
}
